// commons/diy/mch_list/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
      setting: {
        type: Object,
        value: null
      }
  },

  /**
   * 组件的初始数据
   */
  data: {
    longitude: null,
    latitude: null,
    list: []
  },
  ready: function () {
      if (this.properties.setting.is_scroll == 1) {
        this.getLoad();
      }else {
          var that = this;
          this.setData({
              list: that.properties.setting.list
          })
      }
      
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getLoad: function(t) {
        var that = this;
        // 获取经纬度
        wx.getLocation({
            success: function (res) {
                that.setData({
                    longitude: res.longitude,
                    latitude: res.latitude,
                },function () {
                  that.loadShopList()
                })
            },
        })
    },
    loadShopList: function(i) {
        var o = this;
        o.data.no_more ? "function" == typeof i && i() : o.data.loading || (o.setData({
            loading: !0
        }), getApp().request({
            url: getApp().api.mch.shop_list,
            data: {
                page: 1,
                longitude: o.data.longitude,
                latitude: o.data.latitude,
                limit:o.properties.setting.limit
            },
            success: function(t) {
                if (0 == t.code) {
                    if (!t.data.list || !t.data.list.length) return void o.setData({
                        no_more: !0,
                    });
                    o.data.list || (o.data.list = []), o.data.list = o.data.list.concat(t.data.list), 
                    o.setData({
                        list: o.data.list,
                    });
                }
            },
        }));
    },
  }
})
